package me.shibor.study.quartz.demo;

import org.quartz.DateBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey;
import org.quartz.impl.StdSchedulerFactory;

import me.shibor.study.quartz.job.HelloJob;

public class SimpleTriggerExample {

	public static void main(String[] args) throws SchedulerException {

		JobDetail job = JobBuilder.newJob(HelloJob.class).withIdentity("myJob").build();

		Trigger trigger = TriggerBuilder.newTrigger().withIdentity(new TriggerKey("myTrigger", "myTriggerGroup"))
				.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).repeatForever())
				.startAt(DateBuilder.futureDate(10, DateBuilder.IntervalUnit.SECOND)).build();

		Scheduler scheduler = new StdSchedulerFactory().getScheduler();

		scheduler.start();
		scheduler.scheduleJob(job, trigger);

		// Trigger trigger = TriggerBuilder
		// .newTrigger()
		// .withIdentity("dummyTriggerName", "group1")
		// .withSchedule(
		// SimpleScheduleBuilder.simpleSchedule()
		// .withIntervalInSeconds(5).repeatForever())
		// .build();
		//
		// Scheduler scheduler = new StdSchedulerFactory().getScheduler();
		// scheduler.start();
		// scheduler.scheduleJob(job, trigger);

	}

}
